Public Class frmLocLoHang
    Private m_strLoc As String
    Private m_maKho As String
    Private ma_hang As String

    Private m_maloaithuoc As String
    Private frm As Object

#Region "Property"
    Property StrLoc() As String

        Get
            Return m_strLoc
        End Get
        Set(ByVal value As String)
            m_strLoc = value
        End Set
    End Property
#End Region

#Region "New"
    Public Sub New(ByRef frmSource As System.Windows.Forms.Form, ByVal makho As String)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        If frmSource.Name = frmQuanLyLoHang.Name Then
            frm = CType(frmSource, frmQuanLyLoHang)
        ElseIf frmSource.Name = frmLoHang.Name Then
            frm = CType(frmSource, frmLoHang)
        Else

        End If
        m_maKho = makho
        'Khoi Tao Gia Tri Loc Da Luu Cho Form 
        ma_hang = frm.MaHang
        If (ma_hang <> "") Then
            If (ma_hang.Substring(7, 7) = "0000000") Then 'loaithuoc
                txtLoaiThuoc.Text = CLoaiThuocs.GetLoaiThuocByMa(ma_hang).TenLoaiThuoc
            Else
                Dim objThuoc As CThuoc
                objThuoc = CThuocs.GetThuocByMa(ma_hang)
                txtLoaiThuoc.Text = objThuoc.TenThuoc + "-" + objThuoc.DonViTinh
            End If
        End If
        txtTenThuoc.Text = frm.TenHang
        '= CThuocs.GetThuocByMa(ma_hang).TenThuoc
        txtLoHang.Text = frm.LoHang
        txtCCL.Text = frm.CCL
        cmbHSD.Text = frm.SSHSD
        dtpHSD.Text = frm.HSD
        cmbSLTon.Text = frm.SSSLTon
        txtSLTon.Text = frm.SLTon
        'DMKho
        KhoiTaoDMLoaiKho(frm.DMLoaiKho)
    End Sub

    Public Sub KhoiTaoDMLoaiKho(ByVal DMLoaiKhoCheck As String)
        Dim str() As String
        str = DMLoaiKhoCheck.Split("/")
        Dim ary As ArrayList
        ary = CDoiTuongs.GetDoiTuongList(enumDoiTuong.LOAIKHO)
        Dim check As Boolean
        '
        For Each item As CDoiTuong In ary
            check = False
            If (str.Length <> 0) Then
                For Each loaikho As String In str
                    If (item.KH = loaikho) Then
                        check = True
                        Exit For
                    End If
                Next
            End If
            clbxLoaiKho.Items.Add(item, check)
        Next
    End Sub
#End Region

#Region "btnLoc"
    Private Sub btnLoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoc.Click
        'set gia tri loc cho form Quan Ly Lo Hang
        frm.MaHang = ma_hang
        frm.TenHang = txtTenThuoc.Text
        frm.LoHang = txtLoHang.Text
        frm.CCL = txtCCL.Text
        frm.SSHSD = cmbHSD.Text
        frm.HSD = dtpHSD.Value.Date
        frm.SSSLTon = cmbSLTon.Text
        frm.SLTon = txtSLTon.Text
        Dim dmloaikho As String = ""
        For Each itemChecked As Object In Me.clbxLoaiKho.CheckedItems
            Dim objItem As CDoiTuong = itemChecked
            dmloaikho &= objItem.KH & "/"
        Next
        If (dmloaikho <> "") Then
            dmloaikho = dmloaikho.Remove(dmloaikho.Length - 1, 1)
        End If
        frm.DMLoaiKho = dmloaikho
        Me.Close()
    End Sub
#End Region

#Region "txtLoHang"

    Private Sub txtLoHang_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLoHang.DoubleClick
        ShowFrmDMLoHang()
    End Sub

    Private Sub txtLoHang_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLoHang.KeyDown
        If (e.KeyCode = Keys.Enter) Or (e.KeyCode = Keys.F1) Then
            ShowFrmDMLoHang()
        ElseIf e.KeyCode = Keys.Delete And e.Modifiers = Keys.Control Then
            txtLoHang.ReadOnly = False
            txtLoHang.Text = ""
        End If
    End Sub

    Public Sub ShowFrmDMLoHang()
        Dim strsql As String
        strsql = "select distinct(lo) from tblTon where kho = '" & m_maKho & "' and lo is not null"
        Dim frm As New frmChonDanhMucTheoListBox(strsql, "lo", "lo", txtLoHang.Text) 'ffvalue)
        frm.ShowDialog()
        If (Not frm.ValueMember Is Nothing) Then
            txtLoHang.Text = frm.ValueMember
            txtLoHang.ReadOnly = True
        Else
            txtLoHang.Text = ""
        End If
    End Sub
#End Region

#Region "txtLoaiThuoc"
    Private Sub txtLoaiThuoc_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLoaiThuoc.DoubleClick
        ShowFrmChonLoaiThuoc()
    End Sub

    Private Sub txtLoaiThuoc_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLoaiThuoc.KeyDown
        If (e.KeyCode = Keys.Enter) Or (e.KeyCode = Keys.F1) Then
            ShowFrmChonLoaiThuoc()
        End If
        If (e.KeyCode = Keys.Delete) And (e.Modifiers = Keys.Control) Then
            txtLoaiThuoc.Text = ""
            ma_hang = ""
        End If
    End Sub

    Public Sub ShowFrmChonLoaiThuoc()
        Dim frm As New frmChonLoaiThuoc
        frm.ShowDialog()
        If (frm.Ten <> Nothing) Then
            Dim ten As String
            ten = frm.Ten
            txtLoaiThuoc.Text = ten
            If (frm.Loai) Then
                'm_maloaithuoc = CLoaiThuocs.GetLoaiThuocByTen(ten).MaLoaiThuoc
                ma_hang = CLoaiThuocs.GetLoaiThuocByTen(ten).MaLoaiThuoc
            Else
                Dim str() As String
                str = ten.Split("-")
                If (str.Length = 2) Then
                    ma_hang = CThuocs.GetThuocByTenandDVT(str(0).Trim, str(1).Trim).MaThuoc
                End If
            End If
        End If
    End Sub
#End Region

End Class